home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 9 / Night Owl CD-ROM (NOPV9) (Night Owl Publisher) (1993).ISO / 050a / clblkrep.zip / CLBLKREP.S
Text File  |  1993-04-05  |  4KB  |  103 lines

  1. /****************************************************************************
  2.  *   FILENAME:  C:\TSE\MAC\CLBLKREP.S                                       *
  3.  *   AUTHOR  :  "Buddy" E. Ray Asbury, Jr.                                  *
  4.  *   DATE    :  Mon 04-05-1993 10:27:06                                     *
  5.  *   PURPOSE :  While putting together a data file for a macro, I needed    *
  6.  *              to extract just the capital letters of a column block,      *
  7.  *              putting them in front of the block and leaving the block    *
  8.  *              un-touched.  I was suprised when text from outside the      *
  9.  *              had also been replaced.                                     *
  10.  *                                                                          *
  11.  *              After thinking about what happened, I realized that this    *
  12.  *              was caused by the fact that as text was removed, text which *
  13.  *              wasn't originally in the block slowly moved into it, and    *
  14.  *              was subsequently replaced.                                  *
  15.  *                                                                          *
  16.  *              These macros eliminate this from happening by               *
  17.  *              effectively isolating the block by utilizing a temporary    *
  18.  *              buffer.  As a side effect, it will also prevent a           *
  19.  *              replacement string which is longer than the search          *
  20.  *              string from pushing text outside of the marked block.       *
  21.  *              Of course, when the cursor is not actually inside a         *
  22.  *              column block, they function identically to the built- in    *
  23.  *              commands.  Just bind mFind(), mReplace(), and               *
  24.  *              mRepeatFind() to whatever keys you currently have           *
  25.  *              Find(), Replace(), and RepeatFind() bound to.               *
  26.  *                                                                          *
  27.  ****************************************************************************/
  28.  
  29. FORWARD PROC mReplace(INTEGER isARepeat)
  30.  
  31. PROC mFind()
  32.     IF (Find())
  33.         SetGlobalInt("gColReplaceWasLast", FALSE)
  34.     ENDIF
  35. END mFind
  36.  
  37. PROC mRepeatFind()
  38.     IF (GetGlobalInt("gColReplaceWasLast"))
  39.         mReplace(TRUE)
  40.     ELSE
  41.         RepeatFind()
  42.     ENDIF
  43. END mRepeatFind
  44.  
  45. PROC mReplace(INTEGER isARepeat)
  46.     STRING s[69] = "",
  47.            r[69] = "",
  48.            t[11] = "",
  49.            o[11] = ""
  50.     INTEGER cid = GetBufferID(),
  51.             tid,
  52.             loc
  53.             //markingState
  54.  
  55.     IF (IsCursorInBlock() <> _COLUMN_)
  56.         IF Replace()
  57.             SetGlobalInt("gColReplaceWasLast", FALSE)
  58.         ENDIF
  59.     ELSEIF (isARepeat)
  60.         //markingState = Set(Marking, OFF)
  61.         Set(Marking, OFF)
  62.         PushPosition()
  63.         GotoBlockBegin()
  64.         tid = CreateTempBuffer()
  65.         CopyBlock()
  66.         RepeatFind()
  67.         GotoBufferID(cid)
  68.         CopyBlock(_OVERWRITE_)
  69.         PopPosition()
  70.         //markingState = Set(Marking, markingState)
  71.         AbandonFile(tid)
  72.     ELSEIF (Ask("Search for:", s, _FindHistory_) AND
  73.             Length(s))
  74.         IF (NOT Ask("Replace with:", r, _ReplaceHistory_))
  75.             Return()
  76.         ENDIF
  77.         IF (NOT Ask("Options [BGIWX] (Back Global Ignore-case Words reg-eXp):",
  78.             t, _ReplaceOptionsHistory_))
  79.             Return()
  80.         ENDIF
  81.         Upper(t)
  82.         loc = Pos("L", t)
  83.         IF (loc)
  84.             o = SubStr(t, 1, (loc - 1)) +
  85.                 SubStr(t, (loc + 1), (Length(t) - loc))
  86.         ELSE
  87.             o = t
  88.         ENDIF
  89.         //markingState = Set(Marking, OFF)
  90.         Set(Marking, OFF)
  91.         PushPosition()
  92.         GotoBlockBegin()
  93.         tid = CreateTempBuffer()
  94.         CopyBlock()
  95.         Replace(s, r, o)
  96.         GotoBufferID(cid)
  97.         CopyBlock(_OVERWRITE_)
  98.         PopPosition()
  99.         //markingState = Set(Marking, markingState)
  100.         AbandonFile(tid)
  101.         SetGlobalInt("gColReplaceWasLast", TRUE)
  102.     ENDIF
  103. END mReplace